//
//  QAuthViewController.swift
//  Weibo
//
//  Created by 孙成宇 on 15/11/27.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

import SVProgressHUD


class OAuthViewController: UIViewController {

    let webView = UIWebView()
    
    
    @objc private func close(){
    
  //dismissViewControllerAnimated(ture, completion: nil)
    dismissViewControllerAnimated(true, completion: nil)
        
    
    
    }
    override func loadView() {
        view = webView
       webView.delegate = self
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //设置导航条
        
         navigationItem.leftBarButtonItem = UIBarButtonItem(title:"关闭", style: .Plain ,target: self , action: "close")
        
        loadOauthPage()

        
    }
    
    //MARK 加载授权界面
    private func loadOauthPage(){
    
        let urlString = "https://api.weibo.com/oauth2/authorize?" + "client_id=" + client_id + "&redirect_uri=" + redirect_uri
        
        if let url = NSURL(string: urlString){
        
        let request = NSURLRequest(URL: url)
        
        webView.loadRequest(request)
        
    
        }
    
    
    }
    
    
    
    
    

      extension OAuthViewController: UIWebViewDelegate  {
        func webViewDIdFinisheLoad(webView : UIWebView) {
        
        SVProgressHUD.dismiss()
        
        
        }
        func webViewDidStartLoad(webView: UIWebView) {
        
        SVProgressHUD.show()
        
        }
    
    }

    

}
